//
//  SINAStuHomeActivityLeaveTableViewCell.m
//  sinashebao
//
//  Created by  androidlongs on 2018/2/11.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "SINAStuHomeActivityLeaveTableViewCell.h"
#import "SINALabelUtils.h"
#import "SINACircularBeadUtils.h"


@interface SINAStuHomeActivityLeaveTableViewCell()<UITextViewDelegate>

//左视图
@property (weak, nonatomic) IBOutlet UIView *leftView;
@property (weak, nonatomic) IBOutlet UIImageView *leftTitleImageView;
@property (weak, nonatomic) IBOutlet UILabel *leftMsgContentLabel;
@property (weak, nonatomic) IBOutlet UIView *leftCntentParentView;


//右视图
@property (weak, nonatomic) IBOutlet UIView *rightView;
@property (weak, nonatomic) IBOutlet UIImageView *rightTitleImageView;
@property (weak, nonatomic) IBOutlet UILabel *rightMsgContentLabel;
@property (weak, nonatomic) IBOutlet UIView *rightContentParentView;

@end

@implementation SINAStuHomeActivityLeaveTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


-(void)setModel:(SINAStuHomeActiviLeaveModel *)model{
    _model = model;
    NSString *msgUserUid = model.msgUserUid;
    NSString *userUid = [[SINACommonUserHelper share] getUserModel].userUid ;
    
    
    
    if ([msgUserUid isEqualToString:userUid]) {
        //自己的消息
        self.leftView.hidden = YES;
        self.rightView.hidden = NO;
        self.rightView.backgroundColor=[UIColor clearColor];
        self.rightView.frame = CGRectMake(0, 15,mainW, 72);
        
        self.rightMsgContentLabel.text=model.leaveContent;
        self.rightTitleImageView.frame=CGRectMake(CGRectGetWidth(self.rightView.frame)-12-54-12, CGRectGetHeight(self.rightView.frame)/2-54/2, 54, 54);
        self.rightMsgContentLabel.frame=CGRectMake(10, 10, 100, 30);
        [SINALabelUtils updateLabel:self.rightMsgContentLabel andWithString:self.rightMsgContentLabel.text andWithTagWidth:CGRectGetWidth(self.rightView.frame)-61-54-12-12-12-20 andWithTagHeight:3*21 andWithTagFontSize:14];
        self.rightContentParentView.frame=CGRectMake(61, CGRectGetHeight(self.rightView.frame)/2-54/2, CGRectGetWidth(self.rightView.frame)-61-54-12-12-12, 20+CGRectGetHeight(self.rightMsgContentLabel.frame));
        
        [SINACircularBeadUtils makeCircularBead:4 andView:self.rightContentParentView];
        [SINACircularBeadUtils makeCircularView:self.rightTitleImageView];
        [self.rightTitleImageView sd_setImageWithURL:[NSURL URLWithString:model.headerImageUrl] placeholderImage:[UIImage imageNamed:@"默认头像"]] ;
        
        if(CGRectGetHeight(self.rightMsgContentLabel.frame)<40){
            self.rightContentParentView.frame=CGRectMake(61, CGRectGetHeight(self.rightView.frame)/2-54/2, CGRectGetWidth(self.rightView.frame)-61-54-12-12-12,55);
        }
        
    } else {
        //队友的消息
        self.leftView.hidden = NO;
        self.rightView.hidden = YES;
        self.leftView.backgroundColor=[UIColor clearColor];
        self.leftView.frame = CGRectMake(0, 15,mainW, 72);
        self.leftTitleImageView.frame=CGRectMake(12, CGRectGetHeight(self.leftView.frame)/2-54/2, 54, 54);
        self.leftMsgContentLabel.frame=CGRectMake(CGRectGetMaxX(self.leftTitleImageView.frame)+6, CGRectGetHeight(self.leftView.frame)/2-30/2, CGRectGetWidth(self.leftView.frame)-61-12-54-6, 30);
        self.leftMsgContentLabel.backgroundColor=[UIColor whiteColor];
        self.leftMsgContentLabel.text=model.leaveContent;
        
        
        
        
        self.leftMsgContentLabel.text = model.leaveContent;
        self.leftMsgContentLabel.frame=CGRectMake(10,10, 100, 30);
        [SINALabelUtils updateLabel:self.leftMsgContentLabel andWithString:self.leftMsgContentLabel.text andWithTagWidth:CGRectGetWidth(self.leftView.frame)-61-12-54-6-30 andWithTagHeight:3*21 andWithTagFontSize:14];
        
        self.leftCntentParentView.frame=CGRectMake(CGRectGetMaxX(self.leftTitleImageView.frame)+12, CGRectGetHeight(self.leftView.frame)/2-54/2, CGRectGetWidth(self.leftView.frame)-61-12-54-6-20, CGRectGetHeight(self.leftMsgContentLabel.frame)+20);
        
        [SINACircularBeadUtils makeCircularBead:4 andView:self.leftCntentParentView];
        [SINACircularBeadUtils makeCircularView:self.leftTitleImageView];
        
        [self.leftTitleImageView sd_setImageWithURL:[NSURL URLWithString:model.headerImageUrl] placeholderImage:[UIImage imageNamed:@"默认头像"]] ;
        
        if(CGRectGetHeight(self.leftMsgContentLabel.frame)<40){
            self.leftCntentParentView.frame=CGRectMake(CGRectGetMaxX(self.leftTitleImageView.frame)+12, CGRectGetHeight(self.leftView.frame)/2-54/2, CGRectGetWidth(self.leftView.frame)-61-12-54-6-20, 55);
        }
        
        
    }
    
}




@end
